package com.chezhujie.www.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chezhujie.www.domain.Czjexpress;
import com.chezhujie.www.persistence.CzjexpressMapper;
import com.sys.core.exception.ClassCheckException;
import com.sys.core.utils.UUIDUtils;
import com.sys.user.base.service.BaseService;


/**
 * 快递信息
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjexpressService extends BaseService<Czjexpress>{
    @Autowired
    private CzjexpressMapper czjexpressMapper;

    @Autowired
    public void setBaseMapper(CzjexpressMapper czjexpressMapper) {
        this.baseMapper = czjexpressMapper;
    }


    public void checkEntity(Czjexpress czjexpress) throws ClassCheckException {
        if(czjexpress.getExpressId()!=null&&czjexpress.getExpressId().length()>255){
            throw new ClassCheckException("快递信息主键不能超过255个字符");
        }
        if(czjexpress.getExpressCompany()!=null&&czjexpress.getExpressCompany().length()>255){
            throw new ClassCheckException("快递信息快递公司不能超过255个字符");
        }
        if(czjexpress.getCourierNumber()!=null&&czjexpress.getCourierNumber().length()>255){
            throw new ClassCheckException("快递信息快递单号不能超过255个字符");
        }
        if(czjexpress.getOrderCode()!=null&&czjexpress.getOrderCode().length()>255){
            throw new ClassCheckException("快递信息订单编号不能超过255个字符");
        }
    }
    public void checkListEntity(List<Czjexpress> listCzjexpress) throws ClassCheckException {

        for (Czjexpress czjexpress : listCzjexpress) {
            checkEntity(czjexpress);
        }

    }
    
    public Czjexpress getExpressByOrdercode(Map<String, Object> map) {
		return czjexpressMapper.getExpressByOrdercode(map);
	}

	public void insertCzjexpress(Czjexpress czjexpress) {
			if(StringUtils.isBlank(czjexpress.getExpressId())){
				czjexpress.setExpressId(UUIDUtils.getUUID());
				czjexpress.setCreateTime(new Date());
			}
			czjexpressMapper.insert(czjexpress);
	}

	public void updateCzjexpress(Czjexpress czjexpress) {
		czjexpressMapper.update(czjexpress);
		
	}
}
